   

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
//#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]


pub use hello_lib::shared::Shared;

use tracing::{error, info, debug};
use time::{format_description, UtcOffset};
use tracing_subscriber::{
    self, filter::EnvFilter, fmt, fmt::time::OffsetTime, layer::SubscriberExt,
    util::SubscriberInitExt, Registry,
};
use std::sync::Arc;
use tokio;
use tokio::sync::{mpsc, broadcast, broadcast::Receiver};
use anyhow;

type Result<T> = anyhow::Result<T>;


#[tokio::main]
async fn main() -> Result<()> {   

    tracelog_init("debug");

    let shared = Shared::new("config.json", "target/site/pkg", "site/pkg");
    let shared: Arc<Shared> = Arc::new( shared );
    
    hello_lib::run(shared);
    debug!("tauri关闭！");
    
    return Ok(());
}

fn tracelog_init(trace_level: &str) {
    // debug!("当前采用tracing的rolling log模式, 可修改Cargo.toml, 改为基于log4rs的log模式");
    let secs = chrono::Local::now().offset().local_minus_utc();
    let offset = UtcOffset::from_whole_seconds(secs).unwrap();
        
    let env_filter =
        EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(trace_level));    
    let format = "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]";    
        // 写入控制台 stderr
        let formatting_layer =       
            fmt::layer()
            .pretty()               
            .with_writer(std::io::stderr)
            .with_timer(OffsetTime::new(
                offset,
                format_description::parse(format).unwrap(),
            ));
// 注册
        Registry::default()
            .with(env_filter)
            .with(formatting_layer)
            .init();    
    
}
